<template>
    <div class="maxContainer content">
        <div class="formContainer">
            <el-form :inline="true" :model="extensionDataPromotionParam" >
                <el-checkbox-group>
                    <el-form-item label="用户ID">
                    <el-input v-model="extensionDataPromotionParam.query.userId" placeholder="用户ID"></el-input>
                    </el-form-item>
                    <el-form-item label="用户邮箱">
                        <el-input v-model="extensionDataPromotionParam.query.email" placeholder="用户邮箱"></el-input>
                    </el-form-item>
                    <el-form-item label="用户昵称">
                        <el-input v-model="extensionDataPromotionParam.query.nickname" placeholder="用户昵称"></el-input>
                    </el-form-item>
                    <el-form-item label="推广码">
                        <el-input v-model="extensionDataPromotionParam.query.code" placeholder="推广码"></el-input>
                    </el-form-item>
                </el-checkbox-group>
                <el-checkbox-group>
                    <el-form-item label="时间（开始）">
                        <el-date-picker
                        v-model="extensionDataPromotionParam.query.userBeginDate"
                        type="date"
                        placeholder="开始时间">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="时间（结束）">
                        <el-date-picker
                        v-model="extensionDataPromotionParam.query.userEndDate"
                        type="date"
                        placeholder="结束时间">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item>
                        <el-button @click="defaultSearch()">搜索</el-button>
                    </el-form-item>
                    <el-form-item>
                        <el-button @click="onDataExport">导出</el-button>
                    </el-form-item>
                </el-checkbox-group>
            </el-form>
        </div>
        <div class="tableData">
            <el-table :data="tableDataPromotionData" border style="width: 100%">
                <el-table-column prop="userId" label="用户ID" ></el-table-column>
                <el-table-column prop="email" label="用户邮箱" ></el-table-column>
                <el-table-column prop="nickname" label="用户昵称" > </el-table-column>
                <el-table-column prop="code" label="推广码" > </el-table-column>
                <el-table-column prop="totalInviteNum" label="推广总人数" > </el-table-column>
                <el-table-column prop="totalPromotionRevenue" label="推广总收入" > </el-table-column>
                <el-table-column prop="totalPromotionProfit" label="总推广利润" > </el-table-column>
                <el-table-column prop="inviteNum" label="本月推广人数" > </el-table-column>
                <el-table-column prop="popularizeIncome" label="本月推广收入" > </el-table-column>
                <el-table-column prop="boxProfit" label="本月开箱利润" > </el-table-column>
                <el-table-column prop="recoveryProfit" label="本月回收利润" > </el-table-column>
                <el-table-column prop="popularizeProfit" label="本月推广利润" > </el-table-column>
                <el-table-column prop="previousPopularizeProfit" label="上月推广利润" > </el-table-column>
            </el-table>
            <el-pagination
            background
            layout="prev, pager, next"
            :page-count="extensionDataPromotionParam.pageCount"
            @current-change="promotionCurrentPageChange">
        </el-pagination>
        </div>
    </div>
</template>

<script>
import api from '../../../api/Basicpath/index'
export default {
    data() {
      return {
        extensionDataPromotionParam:{
            "currentPage":1,
            "pageSize":3,
            "total":100,
            "pageCount":0,
            "query":{
                "userId":"",
                "email":"",
                "nickname":"",
                "code":"",
                "userBeginDate": new Date(new Date().getFullYear(), new Date().getMonth(), 1),
                "userEndDate": this.currentMonthLast(),
                "state":1,
                "recordTime":new Date(new Date().getFullYear(), new Date().getMonth(), 1)
            }
        },
        tableDataPromotionData: [],
        dataExportReqParama:{}
      }
    },
    methods: {
        currentMonthLast(){
            var date=new Date();
            var currentMonth=date.getMonth();
            var nextMonth=++currentMonth;
            var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
            var oneDay=1000*60*60*24;
            return new Date(nextMonthFirstDay-oneDay);
        },
        defaultSearch(){
            this.extensionDataPromotionParam.currentPage = 1;
            this.extensionDataPromotionParam.pageCount = 1;
            this.onSearch();
        },
        onSearch() {
            this.$axios.post(`${api}/gamemall/promote/search`,this.extensionDataPromotionParam)
				.then( res => {
				if(res.code === 200){                    
                    console.log(res.data);
                    if(res.data==null){
                        this.extensionDataPromotionParam.currentPage = 1;
                        this.extensionDataPromotionParam.pageCount = 0;
                        this.tableDataPromotionData =[];
                    }else{
                        this.tableDataPromotionData = res.data.list;
					    this.extensionDataPromotionParam.pageCount = res.data.pages;
                    }
				}else if(res.code === 500){
					// this.$message({
					// message: res.msg || '请求数据失败',
					// type: 'warning'
					// })
				}
				})
				.catch( err =>{
				// this.$message({
				// 	message: err.msg || '请求数据失败',
				// 	type: 'warning'
				// 	})
                }
            );
        },
        onDataExport() {
            let param = this.dataExportReqParama;
            let url = `${api}/gamemall/promote/export?`;
            url+= 'nickname='+ this.extensionDataPromotionParam.query.nickname +'&';
            url+= 'userId='+ this.extensionDataPromotionParam.query.userId +'&';
            url+= 'email='+ this.extensionDataPromotionParam.query.email +'&';
            url+= 'code='+ this.extensionDataPromotionParam.query.code +'&';
            url+= 'userBeginDate='+ this.extensionDataPromotionParam.query.userBeginDate +'&';
            url+= 'userEndDate='+ this.extensionDataPromotionParam.query.userEndDate +'&';
            url+= 'currentPage='+ this.extensionDataPromotionParam.currentPage +'&';
            url+= 'pageSize='+ this.extensionDataPromotionParam.pageSize +'&';
            url+= 'recordTime='+ this.extensionDataPromotionParam.query.recordTime +'&';
            url+= 'state='+ this.extensionDataPromotionParam.query.state +'&';
            window.open(url, '_blank');
        },
        promotionCurrentPageChange(currentPage) {
            this.extensionDataPromotionParam.currentPage = currentPage;
            this.onSearch();
        }
    },
    created:function (){
      this.onSearch();
    }
};
</script>
<style scoped>
    .content {
        width: 99%;
        height: 99%;
        display: flex;
        flex-direction: column;
        /* justify-content: center; */
        padding-top: 2%;
        margin-left: 0.5%;
        border: 1px solid #EBEEF5;
        background-color: #FFF;
        border-radius: 0.325rem;
        font-family: Avenir,Helvetica,Arial,sans-serif;
    }
    .el-form{
        text-align: left;
        margin-left: 2%;
    }
</style>